
<?php 
session_start();
ob_start();

if (isset($_SESSION["id"]))
    header("Location: http://localhost:82/ntrduc-web2/index3.php?uid=".$users[$index]['id']);
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
        </style>
        <link href="public/css/cssindex3.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="full">
            <div id="banner">

                <img src="public/image/bannerforumr.png">

            </div>
            <div id='cssmenu'>
                <ul>
                    <li class='active'><a href='login.php'><span>Home</span></a></li>
                    <li><a href='#'><span>Products</span></a></li>
                    <li><a href='#'><span>About</span></a></li>
                    <li class='last'><a href='#'><span>Contact</span></a></li>
                </ul>
            </div>
            <div id="noidung">


                <div class="cot2">
                    
                    <form action="" method="post">
                         
<label>UserName :</label>
<input type="text" name="username"/>
<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Login " name="submit"/><br />
                     
</form>
                    
                    <?php require_once 'user.php'; ?>
                        <?php if (isset($_POST['submit'])): ?>
                            <?php
                            $username = $_POST['username'];
                            $password = $_POST['password'];
                            $isOk = FALSE;
                            $index = -1;
                            for ($i = 0; $i < count($users); $i++) {
                                if ((strcmp($users[$i]['username'], $username) == 0) &&
                                        (strcmp($users[$i]['password'], $password) == 0)) {
                                    $isOk = TRUE;
                                    $index = $i;
                                }
                            }
                            if ($isOk) {
                                $_SESSION["id"] = $users[$index]["id"];
                                header("Location: http://localhost:82/ntrduc-web2/index3.php");
                            } else {
                                echo 'Mat khau hoac tai khoan sai';
                            }
                            ?>
                        <?php endif; ?>

                    <?php
                    require_once './model/dbdemo.php';
                    require_once './model/wo.php';
                    require_once './model/paginationdemo.php';
//        require_once './model/keywords.php';
//        $keys = new Keywords();
//        $key = $keys->maxlength();
                    $works = new Works();
                    $paginations = new Pagination();
                    ?>      
                    <?php
                    if (!isset($_GET["page"]))
                        $page = 1;
                    else
                        $page = $_GET["page"];
                    $list = $works->select_index($page);
                    $total = $works->countWords();
                    echo $paginations->Display($page, $total, null, "login.php");
                    ?>
                    <br>                   
                    <table border="1px" align="center">
                        <tr class="works">
                            <td><b>STT</b></td>
                            <td><b>name</b></td>
                            <td><b>description</b></td>
                            <td><b>posted</b></td>
                            
                            
                            <td><b>Images</b></td>
                            
                        </tr>
                        <?php foreach ($list as $item): ?>
                            <tr>
                                <td class="echo"><?php echo$item['id']; ?></td>
                                <td class="bgtable"><a href="<?php echo$item['url']; ?>" style="text-decoration: none">
                                        <?php echo$item['name']; ?></a></td>                                            
                                <td class="bgtable"><?php echo substr($item['description'], 0, 100); ?></td>
                                <td class="echo"><?php $mydate = getdate($item['posted']); ?> 
                                    <?php echo "$mydate[mday] $mydate[month], $mydate[year]"; ?></td>
                                
                                    <td class="echo"><img src="<?php echo$item['image'] ?>" with="50px" height="50px"</td>
                                   
   
                                </td>
                                
                            <?php endforeach; ?>
                        </tr>
                    </table>
                    <br>
                    <?php echo $paginations->Display($page, $total, null, "index3.php"); ?>
                    <br>

                </div>



            </div>
           

            <div id="fotter">@2014 Design by Team 1<br />
                C12TDC. Cao đẳng công nghệ Thủ Đức</div>
        </div>
        <?php
        // put your code here
        ?>
    </body>
</html>
<?php ob_end_flush(); ?>
